﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Events;
using Services;
using CommonModule;


namespace HeaderContent
{
    public class DialogService
    {
        IEventAggregator EvntAggregator;

        public DialogService()
        {
            this.EvntAggregator = SingletonUnityService.Instance.GetByType<IEventAggregator>();
            this.EvntAggregator.GetEvent<BaseEventArgs>().Subscribe(ShowLoginDialog);
        }

        public void ShowLoginDialog(object obj)
        {
            IModelDialog objLoginDialog = SingletonUnityService.Instance.GetTypeByName<IModelDialog>("LoginDialog");
            LoginDialogViewModel objLoginViewModel = new LoginDialogViewModel();
            objLoginDialog.DataContext = objLoginViewModel;
            objLoginDialog.Closed += (s, e) =>
                {
                    if (objLoginDialog.DialogResult == true)
                    {
                        UserCredential objCredentials = new UserCredential();                        
                        objCredentials.UserName = objLoginViewModel.UserName;
                        objCredentials.Password = objLoginViewModel.Password;
                        this.EvntAggregator.GetEvent<CredentialValidateEventArgs>().Publish(objCredentials);
                    }

                };
            objLoginDialog.Show();

        }

    }
}
